package com.party.core.service.mall.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.mall.MallBrandReadDao;
import com.party.core.dao.write.mall.MallBrandWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.mall.MallBrand;
import com.party.core.service.mall.IMallBrandService;
import com.sun.istack.NotNull;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by huangwuming on 2018/3/26/026.
 */
@Service
public class MallBrandService implements IMallBrandService {

    @Autowired
    private MallBrandReadDao mallBrandReadDao;
    @Autowired
    private MallBrandWriteDao mallBrandWriteDao;

    /**
     * 插入商品品牌
     * @param mallGoodsBrand 商品品牌
     * @return 商品品牌id
     */
    @Override
    public String insert(MallBrand mallGoodsBrand) {
        BaseModel.preInsert(mallGoodsBrand);
        boolean resulet = mallBrandWriteDao.insert(mallGoodsBrand);
        if(resulet){
             return mallGoodsBrand.getId();
        }
        return mallGoodsBrand.getId();
    }

    /**
     * 更新商品品牌
     * @param mallGoodsBrand
     * @return
     */
    @Override
    public boolean update(MallBrand mallGoodsBrand) {
        mallGoodsBrand.setUpdateDate(new Date());
        return mallBrandWriteDao.update(mallGoodsBrand);
    }

    /**
     * 逻辑删除商品品牌
     * @param id 商品品牌主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean deleteLogic(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallBrandWriteDao.deleteLogic(id);
    }

    /**
     * 物理删除
     * @param id 商品品牌主键
     * @return 删除结果（true/false）
     */
    @Override
    public boolean delete(@NotNull String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return mallBrandWriteDao.delete(id);
    }

    /**
     * 批量逻辑删除
     * @param ids 商品品牌集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDeleteLogic(@NotNull Set<String> ids) {
        return mallBrandWriteDao.batchDeleteLogic(ids);
    }

    /**
     * 批量物理删除
     * @param ids 商品品牌集合
     * @return 删除结果（true/false）
     */
    @Override
    public boolean batchDelete(@NotNull Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return mallBrandWriteDao.batchDelete(ids);
    }

    /**
     * 获取商品品牌
     * @param id 商品品牌主键
     * @return 商品品牌
     */
    @Override
    public MallBrand get(String id) {
        return mallBrandReadDao.get(id);
    }

    /**
     * 分页查询商品品牌
     * @param mallGoodsBrand
     * @param page 分页信息
     * @return 商品品牌
     */
    @Override
    public List<MallBrand> listPage(MallBrand mallGoodsBrand, Page page) {
        return mallBrandReadDao.listPage(mallGoodsBrand, page);
    }

    /**
     * 查询所有商品品牌
     * @param mallGoodsBrand
     * @return 商品品牌列表
     */
    @Override
    public List<MallBrand> list(MallBrand mallGoodsBrand) {
        return mallBrandReadDao.listPage(mallGoodsBrand,null);
    }

    /**
     *
     * @param ids 商品品牌主键集合
     * @param mallGoodsBrand
     * @param page 分页信息
     * @return
     */
    @Override
    public List<MallBrand> batchList(@NotNull Set<String> ids, MallBrand mallGoodsBrand, Page page) {
        return null;
    }

    @Override
    public List<MallBrand> webListPage(MallBrand goodsBrand, Map<String, Object> params, Page page) {
        return mallBrandReadDao.webListPage(goodsBrand, params, page);
    }

    @Override
    public List<MallBrand> findByCategoryId(String categoryId) {
        return mallBrandReadDao.findByCategoryId(categoryId);
    }

    @Override
    public List<MallBrand> findByName(String name) {
        return mallBrandReadDao.findByName(name);
    }
}
